<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>GPTEX---为ChatGPT而生的latex软件 | 杨一赫的博客</title><meta name="author" content="杨一赫"><meta name="copyright" content="杨一赫"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="GPTEX---为ChatGPT而生的latex软件  用来记录一个GPTEX的开发过程  为什么要做 日常写作，公式图表离不开latex，而chatgpt对latex图表的解读，修改毫无障碍，把图片转化为latex，然后和chatgpt进行交流，过程非常舒适，所以，一个优秀的图转很关键。 但是目前的图转要么是贵，表以及伪代码图等额外package不支持 latexlive 要么是">
<meta property="og:type" content="article">
<meta property="og:title" content="GPTEX---为ChatGPT而生的latex软件">
<meta property="og:url" content="http://yang1he.gitee.io/2023/02/28/GPTEX---%E4%B8%BAChatGPT%E8%80%8C%E7%94%9F%E7%9A%84latex%E8%BD%AF%E4%BB%B6/index.html">
<meta property="og:site_name" content="杨一赫的博客">
<meta property="og:description" content="GPTEX---为ChatGPT而生的latex软件  用来记录一个GPTEX的开发过程  为什么要做 日常写作，公式图表离不开latex，而chatgpt对latex图表的解读，修改毫无障碍，把图片转化为latex，然后和chatgpt进行交流，过程非常舒适，所以，一个优秀的图转很关键。 但是目前的图转要么是贵，表以及伪代码图等额外package不支持 latexlive 要么是">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230228145723183.png">
<meta property="article:published_time" content="2023-02-27T16:00:00.000Z">
<meta property="article:modified_time" content="2023-02-28T07:00:07.418Z">
<meta property="article:author" content="杨一赫">
<meta property="article:tag" content="-应用文章">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230228145723183.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://yang1he.gitee.io/2023/02/28/GPTEX---%E4%B8%BAChatGPT%E8%80%8C%E7%94%9F%E7%9A%84latex%E8%BD%AF%E4%BB%B6/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><meta/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?6b9e2c1c603a1d11d43a9822bdd68c2c";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: {"limitDay":90,"position":"top","messagePrev":"距离上次更新已经","messageNext":"天本文可能会过期"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'GPTEX---为ChatGPT而生的latex软件',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-02-28 15:00:07'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><script src="https://cdn.jsdelivr.net/npm/echarts@5.3.0/dist/echarts.min.js"></script><script src="https://cdn.jsdelivr.net/npm/echarts@4.7.0/map/js/china.min.js"></script><script src="node_modules/simplex-noise/simplex-noise.js"></script><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="杨一赫的博客" type="application/atom+xml">
</head><body><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pace-js/themes/blue/pace-theme-minimal.min.css"/><script src="https://cdn.jsdelivr.net/npm/pace-js/pace.min.js"></script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/favicon2.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">14</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">7</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about"><i class="fa-fw fa fa-heart"></i><span> 关于我</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230228145723183.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">杨一赫的博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about"><i class="fa-fw fa fa-heart"></i><span> 关于我</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">GPTEX---为ChatGPT而生的latex软件</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-02-27T16:00:00.000Z" title="发表于 2023-02-28 00:00:00">2023-02-28</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-02-28T07:00:07.418Z" title="更新于 2023-02-28 15:00:07">2023-02-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%9E%83%E5%9C%BE%E8%BD%AF%E4%BB%B6%E8%87%AA%E9%80%A0/">垃圾软件自造</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="GPTEX---为ChatGPT而生的latex软件"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1
id="gptex---为chatgpt而生的latex软件">GPTEX---为ChatGPT而生的latex软件</h1>
<blockquote>
<p>用来记录一个GPTEX的开发过程</p>
</blockquote>
<h2 id="为什么要做">为什么要做</h2>
<p>日常写作，公式图表离不开latex，而chatgpt对latex图表的解读，修改毫无障碍，把图片转化为latex，然后和chatgpt进行交流，过程非常舒适，所以，一个优秀的图转很关键。</p>
<p>但是目前的图转要么是贵，表以及伪代码图等额外package不支持</p>
<p><a target="_blank" rel="noopener" href="https://www.latexlive.com/">latexlive</a><br />
要么是贵也不好，表以及伪代码图等额外package不支持</p>
<p><a target="_blank" rel="noopener" href="https://mathpix.com/">mathpix</a><br />
要么是单纯不好用，只能当个文字ocr</p>
<p><a target="_blank" rel="noopener" href="https://baimiao.uzero.cn/">白描</a></p>
<div id="echarts9091" style="width: 85%;height: 400px;margin: 0 auto"></div>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.3.0/dist/echarts.min.js"></script>
<script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('echarts9091'));
        // 指定图表的配置项和数据
        var option = option = {
  title: {
    text: '目前情况'
  },
  legend: {
    data: ['白描', 'latexlive', 'mathpix']
  },
  radar: {
    indicator: [
      { name: 'Price', max: 5 },
      { name: 'Functionality', max: 5 },
      { name: 'Convenience', max: 5 }
    ]
  },
  series: [
    {
      name: 'Budget vs spending',
      type: 'radar',
      data: [
        {
          value: [1, 1, 1],
          name: '白描'
        },
        {
          value: [5, 4, 4],
          name: 'latexlive'
        },
        {
          value: [4, 3, 4],
          name: 'mathpix'
        }
      ]
    }
  ]
};
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
</script>
<p>因此，作为一个偷懒专家，有必要做一个省事的软件，更方便的实现与chatgpt的latex交互。</p>
<h2 id="gptex它应该应该有什么">GPTEX——它应该应该有什么</h2>
<p>GPTEX
的名字也代表了我做这个软件的初心，ChatGpt——latex。从日常工作流出发，我觉得GPTEX最核心的流程就简单的三句话</p>
<blockquote>
<ol type="1">
<li><p>快捷键唤醒截图，用鼠标选中范围之后，截下来的图片自动保存剪贴板中</p></li>
<li><p>读取剪贴板的图片，并通过base64编码调用api进行ocr</p></li>
<li><p>ocr之后返回的文本我要放在电脑的剪贴板</p></li>
</ol>
</blockquote>
<p>也就步骤2有分歧，OCR端口是找商用api还是用深度学习自己措一个小模型。先搁置，先搞出整体框架，说干就干</p>
<figure class="highlight txt"><table><tr><td class="code"><pre><span class="line">  ____________________________________________  ___</span><br><span class="line"> /  _____/\______   \__    ___/\_   _____/\   \/  /</span><br><span class="line">/   \  ___ |     ___/ |    |    |    __)_  \     / </span><br><span class="line">\    \_\  \|    |     |    |    |        \ /     \ </span><br><span class="line"> \______  /|____|     |____|   /_______  //___/\  \</span><br><span class="line">        \/                             \/       \_/</span><br></pre></td></tr></table></figure>
<h2 id="工作步骤界定">工作步骤界定</h2>
<div class="mermaid-wrap"><pre class="mermaid-src" hidden>
  graph LR;
    A[安装 Python] --&gt; B[安装相关库];
    B --&gt; C[设计用户界面];
    C --&gt; D[实现快捷键截图功能];
    D --&gt; E[调用 OCR API 接口];
    E --&gt; F[实现 LaTeX 转换];
    F --&gt; G[实现复制粘贴功能];
    G --&gt; H[测试和调试];
    H --&gt; I[发布和分享];
  </pre></div>
<p>设计一个整体框架如上图，查询一下相关资料，打算这样设定</p>
<p><code>安装相关库</code>：可能需要安装一些 Python 库来实现这个任务，如
PyQt5、pyperclip 和 PyTesseract。PyQt5 可以帮助你构建用户界面，pyperclip
可以让你方便地复制和粘贴文本，PyTesseract 是一个 OCR
库，可以帮助你识别图片中的文本。</p>
<p><code>设计用户界面</code>：使用 PyQt5
设计一个简单的窗口，包括一个截图按钮和一个文本框用来显示 OCR
识别的文本。</p>
<p><code>实现快捷键截图功能</code>：使用 Python 库中的 PyAutoGUI
模块来实现快捷键截图功能，你可以使用 PyAutoGUI 中的 hotkey
函数绑定快捷键并截取屏幕上的指定区域。</p>
<p><code>调用 OCR API 接口</code>：选择一个 OCR API 接口，例如 Google
Cloud Vision API、Microsoft Azure OCR API 或者百度 OCR API，并通过相关
Python 库来调用该 API 实现 OCR 识别。</p>
<p><code>实现 LaTeX 转换</code>：通过 Python 编写一个简单的函数，将 OCR
识别得到的文本转换成 LaTeX
语法。这个过程可以使用正则表达式或者字符串替换等方式实现。</p>
<p><code>实现复制粘贴功能</code>：通过 pyperclip 库来实现 OCR 识别得到的
LaTeX 文本的复制和粘贴。</p>
<p><code>测试和调试</code>：在完成软件的编写后，进行测试和调试，确保程序能够正常运行，并且能够准确地将
OCR 识别得到的文本转换成 LaTeX 语法。</p>
<p><code>封装</code>:
最后把软件封装成一个小的EXE文件，然后就可以享受了。</p>
<h2 id="开干">开干</h2>
<h3 id="首先创建个工作环境">首先创建个工作环境</h3>
<p>去conda promp中</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">conda create -n gptex python=<span class="number">3.8</span></span><br></pre></td></tr></table></figure>
<p>有yes点yes，有些库python版本高了不兼容，所以选择了python3.8，接着激活一下</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">conda activate gptex</span><br></pre></td></tr></table></figure>
<p>开始安装相关包</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">pip install PyQt5     <span class="comment"># 创建 GUI 界面</span></span><br><span class="line">pip install requests  <span class="comment"># 进行网络请求</span></span><br><span class="line">pip install pyautogui <span class="comment"># 控制鼠标和键盘</span></span><br><span class="line">pip install keyboard  <span class="comment"># 监听键盘事件</span></span><br><span class="line">pip install PySide2   <span class="comment"># 创建 GUI 界面</span></span><br><span class="line">pip install baidu-aip <span class="comment"># 调用百度 OCR API 进行图片识别</span></span><br><span class="line">pip install pybase64  <span class="comment"># 对二进制数据进行编解码</span></span><br><span class="line">pip install pyinstaller <span class="comment"># 将 Python 脚本打包为可执行文件</span></span><br></pre></td></tr></table></figure>
<p>工作环境先这样配置吧，回来升级再配置环境。</p>
<h3 id="设计一个用户界面">设计一个用户界面</h3>
<p>直接上代码</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"><span class="keyword">from</span> selection_widget <span class="keyword">import</span> SelectionWidget</span><br><span class="line"><span class="keyword">from</span> PyQt5.QtWidgets <span class="keyword">import</span> QApplication, QWidget, QPushButton, QGridLayout, QLabel, QTextEdit,QShortcut,QLineEdit</span><br><span class="line"><span class="keyword">from</span> PyQt5.QtGui <span class="keyword">import</span> QPixmap, QImage,QKeySequence</span><br><span class="line"><span class="keyword">from</span> PyQt5.QtCore <span class="keyword">import</span> Qt</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> base64</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"></span><br><span class="line"><span class="comment"># Google Cloud Vision API 的地址</span></span><br><span class="line">API_URL = <span class="string">&#x27;https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">shot</span>():</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__int__</span>(<span class="params">self</span>):</span><br><span class="line">        self.startSelection()</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">startSelection</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 隐藏主窗口</span></span><br><span class="line">        self.hide()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 监听鼠标按下事件</span></span><br><span class="line">        self.setMouseTracking(<span class="literal">True</span>)</span><br><span class="line">        self.mousePressEvent = self.onMousePress</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">onMousePress</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="comment"># 记录起点</span></span><br><span class="line">        self.start = event.pos()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 监听鼠标移动事件</span></span><br><span class="line">        self.mouseMoveEvent = self.onMouseMove</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 监听鼠标释放事件</span></span><br><span class="line">        self.mouseReleaseEvent = self.onMouseRelease</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">onMouseMove</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="comment"># 绘制矩形</span></span><br><span class="line">        self.selection = QRect(self.start, event.pos()).normalized()</span><br><span class="line">        self.update()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">onMouseRelease</span>(<span class="params">self, event</span>):</span><br><span class="line">        <span class="comment"># 停止监听鼠标事件</span></span><br><span class="line">        self.mousePressEvent = <span class="literal">None</span></span><br><span class="line">        self.mouseMoveEvent = <span class="literal">None</span></span><br><span class="line">        self.mouseReleaseEvent = <span class="literal">None</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Screenshot</span>(<span class="title class_ inherited__">QWidget</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">super</span>().__init__()</span><br><span class="line">        self.initUI()</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">initUI</span>(<span class="params">self</span>):</span><br><span class="line"></span><br><span class="line">        self.shortcutLineEdit = QLineEdit(<span class="string">&quot;&#x27;Ctrl+Alt+m&#x27;&quot;</span>,self)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 创建一个按钮用于保存快捷键设定</span></span><br><span class="line">        self.saveShortcutBtn = QPushButton(<span class="string">&#x27;保存快捷键&#x27;</span>, self)</span><br><span class="line">        self.saveShortcutBtn.clicked.connect(self.saveShortcut)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 创建一个按钮用于截图</span></span><br><span class="line">        self.screenshotBtn = QPushButton(<span class="string">&#x27;截图&#x27;</span>, self)</span><br><span class="line">        self.screenshotBtn.clicked.connect(self.screenshot)</span><br><span class="line">        <span class="comment"># 创建一个文本框用于显示 OCR 识别的文本</span></span><br><span class="line">        self.ocrTextEdit = QTextEdit(self)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 创建网格布局并将文本框和按钮添加到其中</span></span><br><span class="line">        grid = QGridLayout()</span><br><span class="line">        grid.addWidget(QLabel(<span class="string">&#x27;设定快捷键：&#x27;</span>), <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        grid.addWidget(self.shortcutLineEdit, <span class="number">0</span>, <span class="number">1</span>)</span><br><span class="line">        grid.addWidget(self.saveShortcutBtn, <span class="number">0</span>, <span class="number">2</span>)</span><br><span class="line">        grid.addWidget(self.screenshotBtn, <span class="number">1</span>, <span class="number">0</span>)</span><br><span class="line">        grid.addWidget(QLabel(<span class="string">&#x27;OCR 识别结果：&#x27;</span>), <span class="number">2</span>, <span class="number">0</span>, Qt.AlignTop)</span><br><span class="line">        grid.addWidget(self.ocrTextEdit, <span class="number">3</span>, <span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">        self.setLayout(grid)</span><br><span class="line">        self.setGeometry(<span class="number">300</span>, <span class="number">300</span>, <span class="number">450</span>, <span class="number">300</span>)</span><br><span class="line">        self.setWindowTitle(<span class="string">&#x27;截图并 OCR&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">saveShortcut</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 获取文本框中输入的快捷键</span></span><br><span class="line">        shortcut = QKeySequence(self.shortcutLineEdit.text())</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 设置快捷键</span></span><br><span class="line">        self.screenshotBtn.setShortcut(shortcut)</span><br><span class="line"><span class="keyword">def</span> <span class="title function_">screenshot</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="comment"># 获取屏幕截图</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="number">111</span>)</span><br><span class="line">        screenshot = QApplication.primaryScreen().grabWindow(QApplication.desktop().winId())</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 将截图转换为字节流并进行 base64 编码</span></span><br><span class="line">        <span class="built_in">print</span>(<span class="number">222</span>)</span><br><span class="line">        image_bytes = screenshot.toImage().bits().asstring(screenshot.width() * screenshot.height() * <span class="number">4</span>)</span><br><span class="line">        base64_bytes = base64.b64encode(image_bytes)</span><br><span class="line">        <span class="built_in">print</span>(<span class="number">333</span>)</span><br><span class="line">        base64_string = base64_bytes.decode(<span class="string">&#x27;utf-8&#x27;</span>)</span><br><span class="line">        <span class="built_in">print</span>(base64_string)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 构建 OCR 请求的 JSON 数据</span></span><br><span class="line">        request_data = &#123;</span><br><span class="line">            <span class="string">&#x27;requests&#x27;</span>: [&#123;</span><br><span class="line">                <span class="string">&#x27;image&#x27;</span>: &#123;</span><br><span class="line">                    <span class="string">&#x27;content&#x27;</span>: base64_string</span><br><span class="line">                &#125;,</span><br><span class="line">                <span class="string">&#x27;features&#x27;</span>: [&#123;</span><br><span class="line">                    <span class="string">&#x27;type&#x27;</span>: <span class="string">&#x27;TEXT_DETECTION&#x27;</span>,</span><br><span class="line">                    <span class="string">&#x27;maxResults&#x27;</span>: <span class="number">1</span></span><br><span class="line">                &#125;]</span><br><span class="line">            &#125;]</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 发送 OCR 请求并获取响应</span></span><br><span class="line">        response = requests.post(API_URL, json=request_data)</span><br><span class="line">        <span class="keyword">if</span> response.status_code == <span class="number">200</span>:</span><br><span class="line">            response_data = json.loads(response.text)</span><br><span class="line">            ocr_text = response_data[<span class="string">&#x27;responses&#x27;</span>][<span class="number">0</span>][<span class="string">&#x27;fullTextAnnotation&#x27;</span>][<span class="string">&#x27;text&#x27;</span>]</span><br><span class="line">            self.ocrTextEdit.setPlainText(ocr_text)</span><br><span class="line"></span><br><span class="line">            <span class="comment"># 将 OCR 识别的文本复制到剪贴板中</span></span><br><span class="line">            clipboard = QApplication.clipboard()</span><br><span class="line">            clipboard.setText(ocr_text)</span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">接下来，我们将截图转换为字节流并进行 base64 编码，然后构建 OCR 请求的 JSON 数据，该 JSON 数据包含了图像的 base64 编码和 OCR 识别的参数。然后，我们使用 requests.post 方法将 OCR 请求发送到 Google Cloud Vision API，并获取响应。如果响应状态码为 200，则将 OCR 识别的文本显示在文本框中，并将文本复制到剪贴板中。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">请注意，为了使用 Google Cloud Vision API 进行 OCR，您需要先在 Google Cloud Console 上创建一个项目，并启用 Google Cloud Vision API。然后，您需要创建一个 API 密钥，并将其作为参数添加到 API URL 中。在代码中，您需要将 YOUR_API_KEY 替换为您的 API 密钥。</span></span><br><span class="line"><span class="string">另外，请注意，本代码中使用了 requests 库来发送 HTTP 请求，并使用了 json 库来解析 JSON 响应。在使用这些库之前，请确保已经安装它们。您可以通过在终端中运行以下命令来安装它们</span></span><br><span class="line"><span class="string">###</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    app = QApplication(sys.argv)</span><br><span class="line">    screenshot = Screenshot()</span><br><span class="line">    screenshot.show()</span><br><span class="line">    sys.exit(app.exec_())</span><br></pre></td></tr></table></figure>
<p>简单运行下，界面有够简洁的，能用就行哈哈哈，一点点优化，作为一个软件萌新，要学会给自己画大饼，目前大致上长这个样子，有着设定快捷键截图，也有直接截图，OCR结果既保存在下面的TXT窗口中，也保存在你的剪切板里，</p>
<figure>
<img
src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230228131802971.png"
alt="image-20230228131802971" />
<figcaption aria-hidden="true">image-20230228131802971</figcaption>
</figure>
<blockquote>
<p>接下来就是设定一些截图的详细交互</p>
</blockquote>
<h3 id="截图功能实现">截图功能实现</h3>
<p>有现成的，借鉴自大佬@Karbob，搞得很人性化，不符合我的丐版风格，想了想就是左键摁下，画出个区域，截出这个区域的矩形图，所以直接设置个监听过程算了</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">startSelection</span>(<span class="params">self</span>):</span><br><span class="line">       <span class="comment"># 隐藏主窗口</span></span><br><span class="line">       self.hide()</span><br><span class="line">       <span class="comment"># 监听鼠标按下事件</span></span><br><span class="line">       self.setMouseTracking(<span class="literal">True</span>)</span><br><span class="line">       self.mousePressEvent = self.onMousePress</span><br><span class="line"></span><br><span class="line">   <span class="keyword">def</span> <span class="title function_">onMousePress</span>(<span class="params">self, event</span>):</span><br><span class="line">       <span class="comment"># 记录起点</span></span><br><span class="line">       self.start = event.pos()</span><br><span class="line"></span><br><span class="line">       <span class="comment"># 监听鼠标移动事件</span></span><br><span class="line">       self.mouseMoveEvent = self.onMouseMove</span><br><span class="line"></span><br><span class="line">       <span class="comment"># 监听鼠标释放事件</span></span><br><span class="line">       self.mouseReleaseEvent = self.onMouseRelease</span><br><span class="line"></span><br><span class="line">   <span class="keyword">def</span> <span class="title function_">onMouseMove</span>(<span class="params">self, event</span>):</span><br><span class="line">       <span class="comment"># 绘制矩形</span></span><br><span class="line">       self.selection = QRect(self.start, event.pos()).normalized()</span><br><span class="line">       self.update()</span><br><span class="line"></span><br><span class="line">   <span class="keyword">def</span> <span class="title function_">onMouseRelease</span>(<span class="params">self, event</span>):</span><br><span class="line">       <span class="comment"># 停止监听鼠标事件</span></span><br><span class="line">       self.mousePressEvent = <span class="literal">None</span></span><br><span class="line">       self.mouseMoveEvent = <span class="literal">None</span></span><br><span class="line">       self.mouseReleaseEvent = Non</span><br></pre></td></tr></table></figure>
<h3 id="构建ocr的requests">构建OCR的requests</h3>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">screenshot</span>(<span class="params">self</span>):</span><br><span class="line">       <span class="comment"># 获取屏幕截图</span></span><br><span class="line">       screenshot = QApplication.primaryScreen().grabWindow(QApplication.desktop().winId())</span><br><span class="line"></span><br><span class="line">       <span class="comment"># 将截图转换为字节流并进行 base64 编码</span></span><br><span class="line">       image_bytes = screenshot.toImage().bits().asstring(screenshot.width() * screenshot.height() * <span class="number">4</span>)</span><br><span class="line">       base64_bytes = base64.b64encode(image_bytes)</span><br><span class="line">       base64_string = base64_bytes.decode(<span class="string">&#x27;utf-8&#x27;</span>)</span><br><span class="line"></span><br><span class="line">       <span class="comment"># 构建 OCR 请求的 JSON 数据</span></span><br><span class="line">       request_data = &#123;</span><br><span class="line">           <span class="string">&#x27;requests&#x27;</span>: [&#123;</span><br><span class="line">               <span class="string">&#x27;image&#x27;</span>: &#123;</span><br><span class="line">                   <span class="string">&#x27;content&#x27;</span>: base64_string</span><br><span class="line">               &#125;,</span><br><span class="line">               <span class="string">&#x27;features&#x27;</span>: [&#123;</span><br><span class="line">                   <span class="string">&#x27;type&#x27;</span>: <span class="string">&#x27;TEXT_DETECTION&#x27;</span>,</span><br><span class="line">                   <span class="string">&#x27;maxResults&#x27;</span>: <span class="number">1</span></span><br><span class="line">               &#125;]</span><br><span class="line">           &#125;]</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line">       <span class="comment"># 发送 OCR 请求并获取响应</span></span><br><span class="line">       response = requests.post(API_URL, json=request_data)</span><br><span class="line">       <span class="keyword">if</span> response.status_code == <span class="number">200</span>:</span><br><span class="line">           response_data = json.loads(response.text)</span><br><span class="line">           ocr_text = response_data[<span class="string">&#x27;responses&#x27;</span>][<span class="number">0</span>][<span class="string">&#x27;fullTextAnnotation&#x27;</span>][<span class="string">&#x27;text&#x27;</span>]</span><br><span class="line">           self.ocrTextEdit.setPlainText(ocr_text)</span><br><span class="line"></span><br><span class="line">          </span><br></pre></td></tr></table></figure>
<p>有空再写</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://yang1he.gitee.io">杨一赫</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://yang1he.gitee.io/2023/02/28/GPTEX---%E4%B8%BAChatGPT%E8%80%8C%E7%94%9F%E7%9A%84latex%E8%BD%AF%E4%BB%B6/">http://yang1he.gitee.io/2023/02/28/GPTEX---%E4%B8%BAChatGPT%E8%80%8C%E7%94%9F%E7%9A%84latex%E8%BD%AF%E4%BB%B6/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://yang1he.gitee.io" target="_blank">杨一赫的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E5%BA%94%E7%94%A8%E6%96%87%E7%AB%A0/">-应用文章</a></div><div class="post_share"><div class="social-share" data-image="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230228145723183.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/03/03/%E5%A4%9A%E6%A0%87%E7%AD%BE%E5%88%86%E7%B1%BB%E7%9A%84CrossEntropyLoss%E5%88%B0%E5%BA%95%E9%9C%80%E4%B8%8D%E9%9C%80%E8%A6%81One-Hot%E7%BC%96%E7%A0%81/"><img class="prev-cover" src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230303211538791.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">多标签分类的CrossEntropyLoss到底需不需要One-Hot编码</div></div></a></div><div class="next-post pull-right"><a href="/2023/02/24/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96%E6%A1%88%E4%BE%8B%E5%B1%95%E7%A4%BA/"><img class="next-cover" src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230224154947463.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">数据可视化案例展示</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/01/06/Chatpt%E9%AB%98%E6%95%88%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%E2%80%94%E2%80%94%E5%9F%BA%E4%BA%8ETransformer%E6%A8%A1%E5%9E%8B%E5%8E%9F%E7%90%86/" title="Chatgpt高效使用技巧——基于Transformer模型原理"><img class="cover" src="https://img-blog.csdnimg.cn/img_convert/168ab6b97255b7565b515514b6563393.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-01-06</div><div class="title">Chatgpt高效使用技巧——基于Transformer模型原理</div></div></a></div><div><a href="/2022/12/05/%E8%81%9A%E7%B1%BB%E5%88%86%E6%9E%90--%E5%9F%BA%E4%BA%8E%E5%85%B1%E4%BA%AB%E5%8D%95%E8%BD%A6%E6%95%B0%E6%8D%AE%E9%9B%86/" title="聚类分析--基于共享单车数据集"><img class="cover" src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/output_40_0.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-12-05</div><div class="title">聚类分析--基于共享单车数据集</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="gitalk-container"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/favicon2.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">杨一赫</div><div class="author-info__description">阳光开朗大男孩</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">14</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">7</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/yang1he"><i class="fab fa-github"></i><span>gitee</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">平平无奇的网站</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#gptex---%E4%B8%BAchatgpt%E8%80%8C%E7%94%9F%E7%9A%84latex%E8%BD%AF%E4%BB%B6"><span class="toc-number">1.</span> <span class="toc-text">GPTEX---为ChatGPT而生的latex软件</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%81%9A"><span class="toc-number">1.1.</span> <span class="toc-text">为什么要做</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#gptex%E5%AE%83%E5%BA%94%E8%AF%A5%E5%BA%94%E8%AF%A5%E6%9C%89%E4%BB%80%E4%B9%88"><span class="toc-number">1.2.</span> <span class="toc-text">GPTEX——它应该应该有什么</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E6%AD%A5%E9%AA%A4%E7%95%8C%E5%AE%9A"><span class="toc-number">1.3.</span> <span class="toc-text">工作步骤界定</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%80%E5%B9%B2"><span class="toc-number">1.4.</span> <span class="toc-text">开干</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A6%96%E5%85%88%E5%88%9B%E5%BB%BA%E4%B8%AA%E5%B7%A5%E4%BD%9C%E7%8E%AF%E5%A2%83"><span class="toc-number">1.4.1.</span> <span class="toc-text">首先创建个工作环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%BE%E8%AE%A1%E4%B8%80%E4%B8%AA%E7%94%A8%E6%88%B7%E7%95%8C%E9%9D%A2"><span class="toc-number">1.4.2.</span> <span class="toc-text">设计一个用户界面</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%AA%E5%9B%BE%E5%8A%9F%E8%83%BD%E5%AE%9E%E7%8E%B0"><span class="toc-number">1.4.3.</span> <span class="toc-text">截图功能实现</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9E%84%E5%BB%BAocr%E7%9A%84requests"><span class="toc-number">1.4.4.</span> <span class="toc-text">构建OCR的requests</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/06/24/An%20Intelligent%20Mobile%20Prediction%20method/" title="An Intelligent Mobile Prediction method with Mini-batch HTIA-based Seq2Seq Networks"><img src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/model_00.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="An Intelligent Mobile Prediction method with Mini-batch HTIA-based Seq2Seq Networks"/></a><div class="content"><a class="title" href="/2023/06/24/An%20Intelligent%20Mobile%20Prediction%20method/" title="An Intelligent Mobile Prediction method with Mini-batch HTIA-based Seq2Seq Networks">An Intelligent Mobile Prediction method with Mini-batch HTIA-based Seq2Seq Networks</a><time datetime="2023-06-23T16:00:00.000Z" title="发表于 2023-06-24 00:00:00">2023-06-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/03/05/%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E4%BD%A0%E4%B8%AA%E4%BA%BA%E8%B4%A6%E5%8F%B7%E7%9A%84openai%E7%9A%84api/" title="无题"><img src="/img/rick1.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="无题"/></a><div class="content"><a class="title" href="/2023/03/05/%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E4%BD%A0%E4%B8%AA%E4%BA%BA%E8%B4%A6%E5%8F%B7%E7%9A%84openai%E7%9A%84api/" title="无题">无题</a><time datetime="2023-03-05T05:57:17.050Z" title="发表于 2023-03-05 13:57:17">2023-03-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/03/04/%E4%B8%89%E5%88%86%E9%92%9F4%E8%A1%8C%E5%91%BD%E4%BB%A4%E6%9E%84%E5%BB%BAchatgpt%20webapp,%E6%94%AF%E6%8C%81%E9%AB%98%E5%B9%B6%E5%8F%91%E4%BB%A5%E5%8F%8A%E4%B8%8A%E4%B8%8B%E6%96%87%E5%AF%B9%E8%AF%9D%E5%8A%9F%E8%83%BD/" title="三分钟4行命令构建chatgpt webapp,支持高并发以及上下文对话功能"><img src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230305093941469.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="三分钟4行命令构建chatgpt webapp,支持高并发以及上下文对话功能"/></a><div class="content"><a class="title" href="/2023/03/04/%E4%B8%89%E5%88%86%E9%92%9F4%E8%A1%8C%E5%91%BD%E4%BB%A4%E6%9E%84%E5%BB%BAchatgpt%20webapp,%E6%94%AF%E6%8C%81%E9%AB%98%E5%B9%B6%E5%8F%91%E4%BB%A5%E5%8F%8A%E4%B8%8A%E4%B8%8B%E6%96%87%E5%AF%B9%E8%AF%9D%E5%8A%9F%E8%83%BD/" title="三分钟4行命令构建chatgpt webapp,支持高并发以及上下文对话功能">三分钟4行命令构建chatgpt webapp,支持高并发以及上下文对话功能</a><time datetime="2023-03-03T16:00:00.000Z" title="发表于 2023-03-04 00:00:00">2023-03-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/03/03/%E5%A4%9A%E6%A0%87%E7%AD%BE%E5%88%86%E7%B1%BB%E7%9A%84CrossEntropyLoss%E5%88%B0%E5%BA%95%E9%9C%80%E4%B8%8D%E9%9C%80%E8%A6%81One-Hot%E7%BC%96%E7%A0%81/" title="多标签分类的CrossEntropyLoss到底需不需要One-Hot编码"><img src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230303211538791.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="多标签分类的CrossEntropyLoss到底需不需要One-Hot编码"/></a><div class="content"><a class="title" href="/2023/03/03/%E5%A4%9A%E6%A0%87%E7%AD%BE%E5%88%86%E7%B1%BB%E7%9A%84CrossEntropyLoss%E5%88%B0%E5%BA%95%E9%9C%80%E4%B8%8D%E9%9C%80%E8%A6%81One-Hot%E7%BC%96%E7%A0%81/" title="多标签分类的CrossEntropyLoss到底需不需要One-Hot编码">多标签分类的CrossEntropyLoss到底需不需要One-Hot编码</a><time datetime="2023-03-02T16:00:00.000Z" title="发表于 2023-03-03 00:00:00">2023-03-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/02/28/GPTEX---%E4%B8%BAChatGPT%E8%80%8C%E7%94%9F%E7%9A%84latex%E8%BD%AF%E4%BB%B6/" title="GPTEX---为ChatGPT而生的latex软件"><img src="https://nmhjklnm.oss-cn-beijing.aliyuncs.com/article-img/img/image-20230228145723183.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="GPTEX---为ChatGPT而生的latex软件"/></a><div class="content"><a class="title" href="/2023/02/28/GPTEX---%E4%B8%BAChatGPT%E8%80%8C%E7%94%9F%E7%9A%84latex%E8%BD%AF%E4%BB%B6/" title="GPTEX---为ChatGPT而生的latex软件">GPTEX---为ChatGPT而生的latex软件</a><time datetime="2023-02-27T16:00:00.000Z" title="发表于 2023-02-28 00:00:00">2023-02-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023 By 杨一赫</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    chtml: {
      scale: 1.1
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        insertScript: [200, () => {
          document.querySelectorAll('mjx-container').forEach(node => {
            if (node.hasAttribute('display')) {
              btf.wrap(node, 'div', { class: 'mathjax-overflow' })
            } else {
              btf.wrap(node, 'span', { class: 'mathjax-overflow' })
            }
          });
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax/es5/tex-mml-chtml.min.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>(() => {
  const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
  if ($mermaidWrap.length) {
    window.runMermaid = () => {
      window.loadMermaid = true
      const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

      Array.from($mermaidWrap).forEach((item, index) => {
        const mermaidSrc = item.firstElementChild
        const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
        const mermaidID = 'mermaid-' + index
        const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
        mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
          mermaidSrc.insertAdjacentHTML('afterend', svgCode)
        })
      })
    }

    const loadMermaid = () => {
      window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid)
    }

    window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
  }
})()</script><script>function addGitalkSource () {
  const ele = document.createElement('link')
  ele.rel = 'stylesheet'
  ele.href= 'https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.css'
  document.getElementsByTagName('head')[0].appendChild(ele)
}

function loadGitalk () {
  function initGitalk () {
    var gitalk = new Gitalk(Object.assign({
      clientID: '5a73aec03d8a0aeb971f',
      clientSecret: '54ad1c8adab95b382d582c73e9f597781de43525',
      repo: 'comment',
      owner: 'nmhjklnm',
      admin: ['nmhjklnm'],
      id: '00b63ff3cc63f3bfe3720a3991fc8567',
      updateCountCallback: commentCount
    },null))

    gitalk.render('gitalk-container')
  }

  if (typeof Gitalk === 'function') initGitalk()
  else {
    addGitalkSource()
    getScript('https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js').then(initGitalk)
  }
}

function commentCount(n){
  let isCommentCount = document.querySelector('#post-meta .gitalk-comment-count')
  if (isCommentCount) {
    isCommentCount.innerHTML= n
  }
}

if ('Gitalk' === 'Gitalk' || !false) {
  if (false) btf.loadComment(document.getElementById('gitalk-container'), loadGitalk)
  else loadGitalk()
} else {
  function loadOtherComment () {
    loadGitalk()
  }
}</script></div><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="//code.tidio.co/6zvu6bgfljrvvv9rw1y7hzehoriklr03.js" async="async"></script><script>function onTidioChatApiReady() {
  window.tidioChatApi.hide();
  window.tidioChatApi.on("close", function() {
    window.tidioChatApi.hide();
  });
}
if (window.tidioChatApi) {
  window.tidioChatApi.on("ready", onTidioChatApiReady);
} else {
  document.addEventListener("tidioChat-ready", onTidioChatApiReady);
}

var chatBtnFn = () => {
  document.getElementById("chat_btn").addEventListener("click", function(){
    window.tidioChatApi.show();
    window.tidioChatApi.open();
  });
}
chatBtnFn()
</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>